<?php
namespace Andorra;

function loadClass($className, $path = null) {
	if (strpos($className, '\\') !== false) {
		$parts = explode('\\', $className);
		$className = $parts[count($parts) - 1];
	}
	
	$path = $path ? $path : '.';
	$h = opendir($path);
	
	while (($e = readdir($h)) !== false) {
		if ($e == '.' || $e == '..')
			continue;
			
		if (is_dir($e)) {
			loadClass($className, "$path/$e");
		} else if (is_file("$path/$e") && strpos($e, "$className.class") === 0) {
				require_once "$path/$e";
				break;
		}
	}
	
	closedir($h);
}

spl_autoload_register('Andorra\loadClass');
?>